package com.tenglong.teacher.ui.common.activity;


import android.app.ProgressDialog;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.v4.app.FragmentActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.tenglong.teacher.R;


/**
 * Created by Kevin on 2017/12/17.
 */

public class BaseFragemntActivity extends FragmentActivity implements View.OnClickListener {
    private ProgressDialog mProgressDlg;
    private TextView mTitleView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(0);
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(getResources().getColor(R.color.actionbar_color));
        }

    }
    public void setContentView(@LayoutRes int layoutResID) {
        LinearLayout layout =(LinearLayout) View.inflate(this,R.layout.actionbar_applayout,null);
        if(layoutResID!=0) {
            layout.addView(View.inflate(this, layoutResID, null));
        }
        setContentView(layout);
       // getActionBar().setCustomView(layout.findViewById(R.id.actionbar_container));
        ImageButton back= layout.findViewById(R.id.action_button1);
        back.setOnClickListener(this);
        mTitleView=layout.findViewById(R.id.action_text);


    }
    public void setTitle(String title){
        mTitleView.setText(title);


    }
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == android.R.id.home){
            finish();
        }
        return true;
    }

    public void showProgressDialog(String message) {
        if (mProgressDlg == null) {
            mProgressDlg = new ProgressDialog(this);
            mProgressDlg.setMessage(message);
            // mProgressDlg.setCanceledOnTouchOutside(false);
            // mProgressDlg.setCancelable(false);
            mProgressDlg.show();
        }
    }

    public void dismissProgressDialog() {
        if (mProgressDlg != null) {
            mProgressDlg.cancel();
            mProgressDlg = null;
        }
    }

    @Override
    public void onClick(View v) {
        if(v.getId()==R.id.action_button1){
            onBackPressed();
        }
    }

}

